

; Damage Class
; calls take-damage of each collided object and then dies

(load "physics-object.scm")

(define damage%
  (class physics-object%
    
    ; PHYSICS-OBJECT%
    (inherit-field collision-occured
                   collision-list)
    (inherit add-collision)
    ; PUBLIC VARIABLES
    (init-field [damage 0])
    
    ; Inflict Damage
    (define/public (inflict-damage)
      ; call take-damage for each object in collision-list
      (for-each (lambda (object)
                  (when (method-in-interface? 'take-damage (object-interface object))
                    (send object take-damage damage)))
                collision-list))
    
    ; Collide
    (define/override (collide x y collision)
      (when (object? collision)
        (add-collision collision)))
    
    ; Update
    (define/override (update)
      (when collision-occured
        (inflict-damage))
      #f)
    
    ; Constructor/Initialization
    (super-new)))

